package com.andy.customerService.controller;


import com.andy.customerService.entity.User;
import com.andy.customerService.entity.WorkOrder;
import com.andy.customerService.feign.FeignService;
import com.andy.customerService.pojo.request.UserRequestParam;
import com.andy.customerService.service.WorkOrderService;
import com.andy.customerService.vo.JsonBaseResult;
import com.andy.customerService.vo.JsonPageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 工单表 前端控制器
 * </p>
 *
 * @author Andy
 * @since 2021-12-27
 */
@RestController
@RequestMapping("/work-order")
public class WorkOrderController {

    @Autowired
    private FeignService feignService;

    @Autowired
    private WorkOrderService workOrderService;


    /**
     * 测试feign调用user信息
     */
    @PostMapping("/users")
    public JsonPageResult<Object> getUserList(@RequestBody UserRequestParam requestParam) {
        return feignService.getUsers(requestParam);
    }

    /**
     * 新建工单
     *
     * @param workOrder
     */
    @PostMapping("/add")
    public JsonBaseResult<Object> addWorkOrder(@RequestBody WorkOrder workOrder) {
        return workOrderService.addWorkOrder(workOrder);
    }

    /**
     * 根据id修改工单信息
     *
     * @param workOrder
     */
    @PutMapping("/edit")
    public JsonBaseResult<Object> editWorkOrder(@RequestBody WorkOrder workOrder) {
        return workOrderService.editWorkOrderById(workOrder);
    }

    /**
     * 根据id删除工单信息
     * @param id
     */
    @DeleteMapping("/delete")
    public JsonBaseResult<Object> deleteWorkOrder(@RequestParam Long id){
        return workOrderService.deleteWorkOrderById(id);
    }

    /**
     * 查询工单列表
     * @return
     */
    @GetMapping("/list")
    public JsonBaseResult<Object> queryWorkOrderList(){
        return workOrderService.queryWorkOrderList();
    }
}

